﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace KKU.RBSFPP.Web.Administrator.Helper
{
    public static class ValidatePrivilegeLevel
    {
        public static bool Validate(string username, params PrivilegeLevel[] privilegeLevel)
        {
            using (var dctc = new KKU.RBSFPP.Shared.DAC.RBSFPPModelContainer())
            {
                var usersQry = from it in dctc.Members
                               where it.Username.ToLower() == username.ToLower()
                               select it;

                if (usersQry.Any())
                {
                    var user = usersQry.FirstOrDefault();
                    return privilegeLevel.Any(it => (int)it == user.PrivilegeLevelId);
                }
                else
                {
                    return false;
                }
            }
        }
    }
}